<template>
    <div class="content">
        <div class="btns-box">
            <Button type="primary" @click="clearAll" >新建</Button>
            <Button type="primary" @click="saveAdd" >暂存</Button>
            <Button type="primary" :disabled="this.form.status===''" @click="delAll">删除</Button>
            <div class="f-fr">
                <Button type="primary" @click="submitAll">申报</Button>
            </div>
        </div>
        <div class="base-info">
            <h3>基本信息</h3>
        </div>
        <div class="content-body">
            <Form
                :model="form"
                :rules="formRules"
                :data-current="currentIndex"
                class="declare-form"
                ref="form"
                :show-message="false"
            >
                <!-- 第1行 -->
                <Row>
                    <Col class="form-label label-border" span="3">产地证备案号</Col>
                    <Col span="3">
                    <FormItem prop="entMgrNo" class="formInput">
                        <Input v-model="form.entMgrNo" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-top" span="3">组织机构代码</Col>
                    <Col span="3">
                    <FormItem prop="copCode" class="formInput">
                        <Input disabled v-model="form.copCode" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-top" span="3">公司中文名称</Col>
                    <Col span="9">
                    <FormItem prop="companyName" class="formInput">
                        <Input disabled v-model="form.companyName" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第2行 -->
                <Row>
                    <Col class="form-label label-border" span="3">证书号</Col>
                    <Col span="3">
                    <FormItem prop="certNo" class="formInput requireBG">
                        <Input v-model="form.certNo" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-top" span="3">发票号</Col>
                    <Col span="3">
                    <FormItem prop="invNo" class="formInput requireBG">
                        <Input placeholder="英文" v-model="form.invNo" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="3">发票日期</Col>
                    <Col span="3">
                    <FormItem prop="invDate" class="formInput requireBG">
                        <Date-picker @on-change="handleDateChange($event,'invDate')" :value="form.invDate" type="date" placeholder="YYYY-MM-DD"></Date-picker>
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="3">出运日期</Col>
                    <Col span="3">
                    <FormItem prop="intendExpDate" class="formInput requireBG">
                        <Date-picker placement="bottom-end" @on-change="handleDateChange($event,'intendExpDate')" :value.sync="form.intendExpDate" type="date" placeholder="YYYY-MM-DD"></Date-picker>
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第3行 -->
                <Row>
                    <Col class="form-label label-border label-top" span="3">签证机关</Col>
                    <Col span="3">
                    <FormItem prop="orgCodeText" class="formInput requireBG">
                        <Input v-model="form.orgCodeText" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-top" span="3">领证机关</Col>
                    <Col span="3">
                    <FormItem prop="fetchPlaceText" class="formInput requireBG">
                        <Input v-model="form.fetchPlaceText" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="3">申请地址</Col>
                    <Col span="3">
                    <FormItem prop="applyAddress" class="formInput">
                        <Input v-model="form.applyAddress" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="3">申请日期</Col>
                    <Col span="3">
                    <FormItem prop="applyDate" class="formInput requireBG">
                        <Date-picker placement="bottom-end" @on-change="handleDateChange($event,'applyDate')" :value="form.applyDate" type="date" placeholder="YYYY-MM-DD"></Date-picker>
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第4行 -->
                <Row>
                    <Col class="form-label label-border" span="3">申报员姓名</Col>
                    <Col span="3">
                    <FormItem prop="applyName" class="formInput requireBG">
                        <Input placeholder="中文" v-model="form.applyName" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-top" span="3">申报员身份证号</Col>
                    <Col span="3">
                    <FormItem prop="applicant" class="formInput requireBG">
                        <Input v-model="form.applicant" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="3">申报员联系方式</Col>
                    <Col span="3">
                    <FormItem prop="applyTel" class="formInput">
                        <Input v-model="form.applyTel" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="3">目的地国家/地区</Col>
                    <Col span="3">
                    <FormItem prop="destCountry" class="formInput requireBG">
                        <Input v-model="form.destCountry" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第5行 -->
                <Row>
                    <Col class="form-label label-border h63" span="3">出口商</Col>
                    <Col span="9">
                    <FormItem prop="exporter" class="formInput h63 requireBG">
                        <i-input type="textarea" v-model="form.exporter" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft h63" span="3">进口商</Col>
                    <Col span="9">
                    <FormItem prop="consignee" class="formInput h63 requireBG">
                        <i-input type="textarea" v-model="form.consignee" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第6行 -->
                <Row>
                    <Col class="form-label label-border h63" span="3">唛头</Col>
                    <Col span="9">
                    <FormItem prop="mark" class="formInput h63 requireBG">
                        <i-input type="textarea" placeholder="英文,请使用回车换行，不能使用多个空格换行" v-model="form.mark" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft h63" span="3">特殊条款</Col>
                    <Col span="9">
                    <FormItem prop="specialTerms" class="formInput h63">
                        <textarea placeholder="英文,请使用回车换行，不能使用多个空格换行" v-model="form.specialTerms" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第7行 -->
                <Row>
                    <Col class="form-label label-border" span="3">启运港</Col>
                    <Col span="3">
                    <FormItem prop="loadPort" class="formInput">
                        <Input v-model="form.loadPort" placeholder="英文" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="3">卸货港</Col>
                    <Col span="3">
                    <FormItem prop="unloadPort" class="formInput">
                        <Input v-model="form.unloadPort" placeholder="英文" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="3">运输方式</Col>
                    <Col span="3">
                    <FormItem prop="transports " class="formInput">
                        <Input v-model="form.transports" placeholder="英文" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="3">运输工具船名/航次</Col>
                    <Col span="3">
                    <FormItem prop="transportsName" class="formInput">
                        <Input v-model="form.transportsName" placeholder="英文" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第8行 -->
                <Row>
                    <Col class="form-label label-border" span="3">贸易方式</Col>
                    <Col span="3">
                    <FormItem prop="tradeMode" class="formInput">
                        <Select v-model="form.tradeMode" class="small-select">
                            <Option v-for="item in tradeModeList" :value="item.id" :key="item.id">{{item.id}}{{item.name}}</Option>
                        </Select>
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="3">中转国家/地区</Col>
                    <Col span="3">
                    <FormItem prop="transCountry" class="formInput">
                        <Input v-model="form.transCountry" placeholder="支持中文、英文、代码查询" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="3">转运港</Col>
                    <Col span="3">
                    <FormItem prop="transshipmentPort" class="formInput">
                        <Input v-model="form.transshipmentPort" placeholder="英文" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="3">目的港</Col>
                    <Col span="3">
                    <FormItem prop="destPort" class="formInput">
                        <Input v-model="form.destPort" placeholder="英文" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第9行 -->
                <Row>
                    <Col class="form-label label-border h63" span="3">运输细节</Col>
                    <Col span="9">
                    <FormItem prop="transDetails" class="formInput h63 requireBG">
                        <i-input type="textarea" v-model="form.transDetails" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft h63" span="3">申请书备注</Col>
                    <Col span="9">
                    <FormItem prop="applicationNotes" class="formInput h63">
                        <textarea v-model="form.applicationNotes" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第10行 -->
                <Row>
                    <Col class="form-label label-border" span="3">FOB值（美元）</Col>
                    <Col span="3">
                    <FormItem prop="fob" class="formInput">
                        <Input v-model="form.fob" placeholder="根据货物信息累计" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="3">总金额</Col>
                    <Col span="3">
                    <FormItem prop="totalAmount" class="formInput">
                        <Input v-model="form.totalAmount" placeholder="根据货物信息累计" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="3">货币单位</Col>
                    <Col span="3">
                    <FormItem prop="monetaryUnit" class="formInput requireBG">
                        <Input v-model="form.monetaryUnit" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="3">发票特殊条款</Col>
                    <Col span="3">
                    <FormItem prop="specialTerms" class="formInput">
                        <Input v-model="form.specialTerms" placeholder="英文" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第11行 -->
                <Row>
                    <Col class="form-label label-border label-bottom" span="3">价格条款</Col>
                    <Col span="3">
                    <FormItem prop="priceTerms" class="formInput requireBG">
                        <Input v-model="form.priceTerms" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft label-bottom" span="3">合同号</Col>
                    <Col span="3">
                    <FormItem prop="contractNo" class="formInput">
                        <Input v-model="form.contractNo" placeholder="英文" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft label-bottom" span="3">信用证号</Col>
                    <Col span="3">
                    <FormItem prop="lcno " class="formInput">
                        <Input v-model="form.lcno" />
                    </FormItem>
                    </Col>
                    <Col span="3">
                    <FormItem class="formInput">
                        <Input />
                    </FormItem>
                    </Col>
                    <Col span="3">
                    <FormItem class="formInput">
                        <Input />
                    </FormItem>
                    </Col>
                </Row>
            </Form>
            <div class="base-info">
                <h3>货物信息</h3>
            </div>
            <Form
                :model="good"
                :rules="rules"
                :data-current="currentIndex"
                class="declare-form"
                ref="good"
                :show-message="false"
            >
                <!-- 第1行 -->
                <Row>
                    <Col class="form-label label-border label-top" span="18"></Col>
                    <Col class="form-label label-border label-top" span="3">序号</Col>
                    <Col span="3">
                    <FormItem prop="serialNumber " class="formInput">
                        <Input disabled v-model="good.serialNumber" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第2行 -->
                <Row>
                    <Col class="form-label label-border" span="3">HS编码</Col>
                    <Col span="3">
                    <FormItem prop="hsCode" class="formInput requireBG">
                        <Input v-model="good.hsCode" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="3">原产地标准</Col>
                    <Col span="3">
                    <FormItem prop="originStandard" class="formInput">
                        <Select v-model="form.originStandard" class="small-select">
                            <Option v-for="item in originStandardList" :value="item.id" :key="item.id">{{item.id}}  {{item.name}}</Option>
                        </Select>
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="3">原产地标准辅助页</Col>
                    <Col span="3">
                    <FormItem prop="originStandardAuxiliary " class="formInput">
                        <Input v-model="good.originStandardAuxiliary" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="3">非原产成分</Col>
                    <Col span="2">
                    <FormItem prop="nonOriginalIngredients " class="formInput requireBG">
                        <inputNumber v-model="good.nonOriginalIngredients" />
                    </FormItem>

                    </Col>
                    <Col span="1">
                    <FormItem prop="bit " class="formInput">
                        <Input disabled v-model="bit" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第3行 -->
                <Row>
                    <Col class="form-label label-border h63" span="3">货物中文名称</Col>
                    <Col span="9">
                    <FormItem prop="chineseName" class="formInput h63 requireBG">
                        <i-input type="textarea" placeholder="英文,请使用回车换行，不能使用多个空格换行" v-model="good.chineseName" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft h63 " span="3">货物英文名称</Col>
                    <Col span="9">
                    <FormItem prop="englishName" class="formInput h63 requireBG">
                        <i-input type="textarea" placeholder="英文,请使用回车换行，不能使用多个空格换行" v-model="good.englishName" />
                    </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col :span="12">
                    <Row>
                        <Col class="form-label label-border" span="6">包装件数</Col>
                        <Col span="4">
                        <FormItem prop="packageNum" class="formInput">
                            <inputNumber placeholder="数字" v-model="good.packageNum" />
                        </FormItem>
                        </Col>
                        <Col span="2">
                        <FormItem prop="packageUnit" class="formInput">
                            <Input placeholder="英文单位" v-model="good.packageUnit" />
                        </FormItem>
                        </Col>
                        <Col class="form-label label-border-noleft" span="6">数/重量单位</Col>
                        <Col span="2">
                        <FormItem prop="goodsQuantity" class="formInput requireBG">
                            <inputNumber v-model="good.goodsQuantity" />
                        </FormItem>
                        </Col>
                        <Col span="2">
                        <FormItem prop="goodsUnitE" class="formInput requireBG">
                            <Input placeholder="英文单位" v-model="good.goodsUnitE" />
                        </FormItem>
                        </Col>
                        <Col span="2">
                        <FormItem prop="goodsUnit" class="formInput requireBG">
                            <Input placeholder="中文单位" v-model="good.goodsUnit" />
                        </FormItem>
                        </Col>
                    </Row>
                    <Row>
                        <Col class="form-label label-border" span="6">辅助数量/单位</Col>
                        <Col span="4">
                        <FormItem prop="auxiliaryNum" class="formInput">
                            <inputNumber placeholder="数字" v-model="good.auxiliaryNum" />
                        </FormItem>
                        </Col>
                        <Col span="2">
                        <FormItem prop="auxiliaryUnit" class="formInput">
                            <Input placeholder="英文单位" v-model="good.auxiliaryUnit" />
                        </FormItem>
                        </Col>
                        <Col class="form-label label-border-noleft" span="6">第二位辅助数量/单位</Col>
                        <Col span="4">
                        <FormItem prop="secondAuxiliaryNum" class="formInput">
                            <inputNumber placeholder="数字" v-model="good.secondAuxiliaryNum" />
                        </FormItem>
                        </Col>
                        <Col span="2">
                        <FormItem prop="secondAuxiliaryUnit" class="formInput">
                            <Input placeholder="英文单位" v-model="good.secondAuxiliaryUnit" />
                        </FormItem>
                        </Col>
                    </Row>
                    <Row>
                        <Col class="form-label label-border" span="6">发票单价</Col>
                        <Col span="6">
                        <FormItem prop="invoicePrice" class="formInput">
                            <inputNumber placeholder="数字" v-model="good.invoicePrice" />
                        </FormItem>
                        </Col>
                        <Col class="form-label label-border-noleft" span="6">(FOB)发票金额</Col>
                        <Col span="4">
                        <FormItem prop="invoiceAmount" class="formInput requireBG">
                            <inputNumber placeholder="数字" v-model="good.invoiceAmount" />
                        </FormItem>
                        </Col>
                        <Col span="2">
                        <FormItem prop="invoiceUnit" class="formInput">
                            <Input placeholder="USD" v-model="good.invoiceUnit" />
                        </FormItem>
                        </Col>
                    </Row>
                    <Row>
                        <Col class="form-label label-border" span="6">生产商代码</Col>
                        <Col span="6">
                        <FormItem prop="manufacturerCode" class="formInput requireBG">
                            <Input v-model="good.manufacturerCode" />
                        </FormItem>
                        </Col>
                        <Col class="form-label label-border-noleft" span="6">FOB值（美元）</Col>
                        <Col span="4">
                        <FormItem prop="fob" class="formInput requireBG">
                            <inputNumber placeholder="数字" v-model="good.fob" />
                        </FormItem>
                        </Col>
                        <Col span="2">
                        <FormItem prop="fobUnit" class="formInput">
                            <Input placeholder="USD" v-model="good.fobUnit" />
                        </FormItem>
                        </Col>
                    </Row>
                    </Col>
                    <Col :span="12">
                    <Col class="form-label label-border h70" span="6">货物描述</Col>
                    <Col span="18">
                    <FormItem prop="goodsDesc" class="formInput h70 requireBG">
                        <i-input type="textarea" placeholder="货物描述方法填写规则：包装件数英文（包装件数数字）包装单位 OF 货物英文名，例：FIFTY SIX (56) EA OF WERQQWER" v-model="good.goodsDesc" />
                    </FormItem>
                    </Col>
                    </Col>
                </Row>
                <!-- 第10行 -->
                <Row>
                    <Col class="form-label label-border label-bottom" span="3">生产商名称</Col>
                    <Col span="3">
                    <FormItem prop="manufacturerName" class="formInput requireBG">
                        <Input v-model="good.manufacturerName" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft label-bottom" span="3">联系人</Col>
                    <Col span="3">
                    <FormItem prop="contacts" class="formInput requireBG">
                        <Input v-model="good.contacts" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft label-bottom" span="3">联系电话</Col>
                    <Col span="3">
                    <FormItem prop="telephone " class="formInput">
                        <Input v-model="good.telephone" />
                    </FormItem>
                    </Col>
                    <Col span="3">
                    <FormItem prop="contacts " class="formInput">
                        <Input v-model="form.contacts" />
                    </FormItem>
                    </Col>
                    <Col span="3">
                    <FormItem
                        prop="telephone
            "
                        class="formInput"
                    >
                        <Input v-model="form.telephone" />
                    </FormItem>
                    </Col>
                </Row>
            </Form>
            <div class="btns-box mt10">
                <Button type="primary" @click="newGood">新建</Button>
                <Button type="primary" @click="saveGood">保存</Button>
                <Button type="primary" @click="delGood">删除</Button>
            </div>
            <div class="mt10">
                <Table border highlight-row @on-current-change="changeNow" :columns="columns" @on-selection-change="getSectedGood" :data="this.form.goodsList">
                    <template slot-scope="{ row }" slot="goodsQuantity">
                        {{ row.goodsQuantity}}{{row.goodsUnitE}}
                    </template>
                    <template slot-scope="{ row }" slot="packageNum">
                        {{ row.packageNum }}{{row.packageUnit}}
                    </template>
                </Table>
            </div>
        </div>
    </div>
</template>
<script>
import { mapState, mapMutations } from 'vuex'
import { queryTeacherList } from '@/api/userManage'
import { addCertificate, saveCertificate, getCertificate, delCertificate } from '@/api/certiData'
import $ from 'jquery'
export default {
    inject: ['nextPageReload', 'reloadPage'],
    props: {
        id: {
            type: String,
            default: ''
        }
    },
    data () {
        return {
            now: {},
            goodStatus: 0,
            selected: [],
            btnDisabled: false,
            columns: [
                {
                    type: 'selection',
                    width: 60,
                    align: 'center'
                },
                {
                    title: '序号',
                    type: 'index',
                    width: 60,
                    align: 'center'
                },
                {
                    title: 'HS编码',
                    key: 'hsCode'
                },
                {
                    title: '货物名称（中文）',
                    key: 'chineseName'
                },
                {
                    title: '数量/单位',
                    slot: 'goodsQuantity'
                }, {
                    title: '包装件数/单位',
                    slot: 'packageNum'
                }
            ],
            good: {
                serialNumber: '', // 序号
                hsCode: '', // HS编码
                originStandard: '', // 原产地标准
                originStandardAuxiliary: '', // 原产地标准辅助页
                nonOriginalIngredients: null, // 非原产成分
                chineseName: '', // 货物中文名称
                englishName: '', // 货物英文名称
                packageNum: null, // 包装件数
                packageUnit: '', // 英文单位
                goodsQuantity: null, // 数量
                goodsUnitE: '', // 英文
                goodsUnit: '', // 中文
                goodsDesc: '', // 货物描述
                auxiliaryNum: null, // 辅助数量
                auxiliaryUnit: '', // 辅助单位
                secondAuxiliaryNum: null, // 第二辅助数量
                secondAuxiliaryUnit: '', // 第二辅助单位
                invoicePrice: null, // 发票单价
                invoiceAmount: null, // (FOB)发票金额
                invoiceUnit: '', // 发票金额单位
                manufacturerCode: '', // 生产商代码
                fob: null, // FOB值（美元）
                fobUnit: '', // FOB单位
                manufacturerName: '', // 生产商名称
                contacts: '', // 联系人
                telephone: ''// 联系电话
            },
            currentIndex: 0,
            cName: '', // 公司中文名称
            bit: '%',
            usd: 'USD',
            form: {
                declareNo: '',
                entMgrNo: '', // 产地证备案号
                copCode: '', // 组织机构代码
                companyName: '',
                certNo: '', // 证书号
                invNo: '', // 发票号
                invDate: '', // 发票日期
                intendExpDate: '', // 出运日期
                orgCodeText: '', // 签证机关
                fetchPlaceText: '', // 领证机关
                applyAddress: '', // 申请地址
                applyDate: '', // 申请日期
                applyName: '', // 申报员姓名
                applicant: '', // 申报员身份证号
                applyTel: '', // 申报员联系方式
                destCountry: '', // 目的地国家/地区
                exporter: '', // 出口商
                consignee: '', // 进口商
                mark: '', // 唛头
                specialTerms: '', // 特殊条款
                loadPort: '', // 启运港
                unloadPort: '', // 卸货港
                transports: '', // 运输方式
                transportsName: '', // 运输工具船名/航次
                tradeMode: '', // 贸易方式
                transCountry: '', // 中转国家/地区
                transshipmentPort: '', // 转运港
                destPort: '', // 目的港,
                transDetails: '', // 运输细节
                applicationNotes: '', // 申请书备注
                fob: '', // FOB值（美元）
                totalAmount: '', // 总金额
                monetaryUnit: '', // 货币单位
                priceTerms: '', // 价格条款
                contractNo: '', // 合同号
                lcno: '', // 信用证号
                status: '', // 0 暂存 1申报
                type: '',
                originId: '', // 用于删除
                goodsList: []

            },
            formRules: {
                certNo: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                invNo: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // 发票日期
                invDate: [
                    { required: true, message: '请选择日期', trigger: 'change,blur' }

                ],
                // 出运日期
                intendExpDate: [
                    {
                        required: true,
                        message: '',
                        trigger: 'change,blur'
                    }
                ],
                // 签证机关
                orgCodeText: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // 领证机关
                fetchPlaceText: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // 申请日期
                applyDate: [
                    {
                        required: true,
                        message: '',
                        trigger: 'change,blur'
                    }
                ],
                // 申报员姓名
                applyName: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // 申报员身份证号
                applicant: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // 目的地国家/地区
                destCountry: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // 出口商
                exporter: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // 进口商
                consignee: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // 唛头
                mark: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // 运输细节
                transDetails: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // 货币单位
                monetaryUnit: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // 价格条款
                priceTerms: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ]

            },
            rules: {
                // HS编码
                hsCode: [ {
                    required: true,
                    message: '',
                    trigger: 'blur'
                }],
                // 非原产成分
                nonOriginalIngredients: [ {
                    type: 'number',
                    required: true,
                    message: '',
                    trigger: 'change'
                }],
                // 中文名称
                chineseName: [ {
                    required: true,
                    message: '',
                    trigger: 'blur'
                }],
                // 英文名称
                englishName: [ {
                    required: true,
                    message: '',
                    trigger: 'blur'
                }],
                // 数量
                goodsQuantity: [ {
                    type: 'integer',
                    required: true,
                    message: '',
                    trigger: 'change'
                }],
                // 英文
                goodsUnitE: [ {
                    required: true,
                    message: '',
                    trigger: 'blur'
                }],
                // 中文
                goodsUnit: [ {
                    required: true,
                    message: '',
                    trigger: 'blur'
                }],
                // fbo发票金额
                invoiceAmount: [ {
                    type: 'number',
                    required: true,
                    message: '',
                    trigger: 'change'
                }],
                // 生产商代码
                manufacturerCode: [ {
                    required: true,
                    message: '',
                    trigger: 'blur'
                }],
                // FOB值（美元）
                fob: [ {
                    type: 'number',
                    required: true,
                    message: '',
                    trigger: 'change'
                }],
                // 货物描述
                goodsDesc: [ {
                    required: true,
                    message: '',
                    trigger: 'blur'
                }],
                // 生产商名称
                manufacturerName: [ {
                    required: true,
                    message: '',
                    trigger: 'blur'
                }],
                // 联系人
                contacts: [ {
                    required: true,
                    message: '',
                    trigger: 'blur'
                }]

            },
            tips: {
                feeRate: ''
            },
            tradeModeList: [
                { id: 0, name: '其他贸易方式' },
                { id: 1, name: '一般贸易' },
                { id: 2, name: '来料加工贸易' },
                { id: 3, name: '进料加工贸易' },
                { id: 4, name: '外商投资' },
                { id: 5, name: '易贷贸易' },
                { id: 6, name: '补偿贸易' },
                { id: 7, name: '边境贸易' },
                { id: 8, name: '展卖贸易' },
                { id: 9, name: '零售贸易' },
                { id: 10, name: '无偿援助' },
                { id: 33, name: '边民互市' }
            ],
            originStandardList: [
                { id: 'F', name: 'F' },
                { id: 'P', name: 'P' },
                { id: 'PK', name: 'PK' },
                { id: 'W', name: 'W' },
                { id: 'Y', name: 'Y' }
            ]
        }
    },
    computed: {
        ...mapState({
            isTeacher: (state) => state.user.roleType === '3',
            userId: (state) => state.user.userId
        })
    },
    mounted () {
        this.good.serialNumber = this.form.goodsList.length + 1
        this.form.type = this.$route.query.type
        let certNo = this.$route.query.certNo
        if (certNo) {
            getCertificate(certNo).then((res) => {
                this.form = Object.assign(this.form, res.data.data.certificate)
                this.form.goodsList = res.data.data.goodsList
            })
        } else {
            this.getAdd()
        }
        let that = this
        let h = $
        if (this.$el) {
            $(this.$el).on('keyup', 'input', function (e) {
                if (e.keyCode == 13) {
                    var index = h('input:text').index(h(e.target))
                    console.log(index)
                    that.getInput(index)
                }
            })
        }
    },
    methods: {
        ...mapMutations(['removeTagNav']),
        getInput (index) {
            var h = $
            h('input:text')[index + 1].focus()
        },
        handleDateChange (v, key) {
            this.form[key] = v
        },
        getAdd () {
            addCertificate().then(res => {
                this.form.companyName = res.data.data.companyName
                this.form.copCode = res.data.data.copCode
            })
        },
        saveAdd () {
            this.form.status = 0
            saveCertificate(this.form).then(res => {
                if (res.data.code != '0000') {
                    this.$Message.error(res.data.data)
                    return
                }
                this.$Message.success('成功')
            })
        },
        queryTeaList () {
            return queryTeacherList({
                pageNum: 1,
                pageSize: 9999
            }).then((res) => {
                if (res.data.code === '0000') {
                    const data = res.data.data
                    this.teaList = Object.freeze(
                        data.list.map((item) => ({
                            value: item.userId,
                            label: item.realName
                        }))
                    )
                }
            })
        },
        handleCancel () {
            this.removeTagNav(this.$route)
            this.$router.replace({
                name: 'classManageList'
            })
        },
        clearAll () {
            /* this.$router.push({
                name: 'certAdd'
            }) */
            if (this.$route.query.certNo) {
                var types = {
                    C: 'normalCert',
                    B: 'asiaCert',
                    G: 'hpCert',
                    E: 'chinaCert'
                }
                console.log(this.$route.query.type)
                let type = this.$route.query.type
                this.nextPageReload()
                this.$router.push({
                    name: types[type],
                    query: {
                        type: type
                    }
                })
            } else {
                Object.keys(this.form).forEach(key => {
                    if (key == 'goodsList') {
                        this.form[key] = []
                        return
                    }
                    this.form[key] = null
                })
            }
        },
        submitAll () {
            this.$refs.form.validate((v) => {
                if (v) {
                    if (this.form.goodsList.length > 0) {
                        this.form.status = 1 // 申报
                        saveCertificate(this.form).then(res => {
                            if (res.data.code != '0000') {
                                this.$Message.error(res.data.msg)
                                return
                            }
                            this.$Message.success('成功')
                            this.nextPageReload()
                            this.$router.push({
                                name: 'certList'
                            })
                        })
                    } else {
                        this.$Message.error('请添加货物')
                    }
                }
            })
        },
        makeFileAll () {

        },
        delAll () {
            delCertificate({ originIds: this.form.originId }).then(res => {
                if (res.data.code === '0000') {
                    this.$Message.success('删除成功')
                    this.nextPageReload()
                    this.$router.push({
                        name: 'certList'
                    })
                } else {
                    this.$Message.error(res.data.msg)
                }
            })
        },
        newGood () {
            Object.keys(this.good).forEach(key => {
                console.log(key)
                /* if (arr.indexOf(key) > -1) {
                    this.good[key] = null
                } else {

                } */
                this.good[key] = null
            })
            this.good.serialNumber = this.form.goodsList.length + 1
            this.goodStatus = 0
        },
        saveGood () {
            console.log()
            var objString = JSON.stringify(this.good)
            var obj2 = JSON.parse(objString)
            if (this.goodStatus) {
                this.form.goodsList.splice(this.now, 1, obj2)
            } else {
                this.form.goodsList.push(obj2)
                this.newGood()
                this.good.serialNumber = this.form.goodsList.length + 1
            }
        },
        delGood () {
            // 先删除
            this.selected.map((item, index) => {
                this.form.goodsList.splice(item.serialNumber - 1, 1)
            })
            // 再重新设置索引
            this.form.goodsList.map((item, index) => {
                item.serialNumber = index + 1
            })
            this.good.serialNumber = this.form.goodsList.length + 1
            this.goodStatus = 0
        },
        sendToSingleWindow () {

        },
        getSectedGood (data) {
            console.log(data)
            this.selected = data
        },
        changeNow (data) {
            this.now = data.serialNumber
            var str = JSON.stringify(data)
            var obj = JSON.parse(str)
            this.good = obj
            this.goodStatus = 1
            this.$refs.good.validate((v) => {})
        }
    }
}
</script>
<style lang="less">
.small-select {
    height: 20px;
    line-height: 20px;
    .ivu-select-selection{
        height: 20px;
        line-height: 20px;
        border-radius: 0px;
    }
    .ivu-select-single .ivu-select-selection .ivu-select-placeholder, .ivu-select-single .ivu-select-selection .ivu-select-selected-value{
        height: 20px;
        line-height: 20px;
    }
}
.h63 {
        height: 63px;
        line-height: 63px;
        textarea{
        height:63px !important;
        }
    }
    .h70 {
        textarea{
        height:76px !important;
        }
    }
</style>
<style lang="less" scoped>
.h63 {
  height: 63px;
  line-height: 63px;
   .ivu-input{
      height:63px;
  }
}
.label-bottom {
  border-bottom: 1px solid #b7b7b7;
}
.label-top {
  border-top: 1px solid #b7b7b7;
}
.label-border {
  border-top: 1px solid #b7b7b7;
  border-left: 1px solid #b7b7b7;
}
.label-border-noleft {
  border-top: 1px solid #b7b7b7;
}
.btns-box {
  .ivu-btn {
    font-size: 12px;
    height: 24px;
    line-height: 12px;
    padding: 3px 14px;
    font-family: "Microsoft YaHei";
    border-radius: 2px;
  }
  button {
    margin-right: 1px;
    margin-bottom: 1px;
  }
}
.content-body {
  margin-top: 8px;
  width: 100%;
  position: relative;
  overflow: hidden;
}
.formInput {
  textarea {
    width: 100%;
    height: 63px;
    border-color: #b7b7b7;
  }
  select {
      height:20px;
      line-height: 20px;
  }
}
.base-info {
  margin-top: 10px;
  h3 {
    color: #1291cc;
    font-size: 13px;
  }
}
.h70 {
  height: 76px;
  line-height: 76px;
  textarea {
    height: 76px;
  }
}
.mt10{
    margin-top:10px;
}
</style>
